home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / pack / crunchmania / crmdata.s < prev    next >
Text File  |  1980-01-03  |  16KB  |  775 lines

  1. *********************************
  2. ***  CrMData V1.01            ***
  3. ***  (c) 1993 Thomas Schwarz  ***
  4. *********************************
  5.     incdir    dh0:ass/Include/
  6.     include    exec/exec_lib.i
  7.     include    dos/dos_lib.i
  8.     include    dos/dosextens.i
  9.     include    utility/tagitem.i
  10.     incdir    dh1:t/ass/Include/
  11.     include    libraries/CrM.i
  12.     include    libraries/CrM_lib.i
  13. *************************************************
  14. CALL    MACRO
  15.     jsr    _LVO\1(a6)
  16.     ENDM
  17. CALLEXEC MACRO
  18.     move.l    4.w,a6
  19.     CALL    \1
  20.     ENDM
  21. CALLCRM    MACRO
  22.     move.l    _CrMBase(pc),a6
  23.     CALL    \1
  24.     ENDM
  25. CALLDOS MACRO
  26.     move.l    _DOSBase(pc),a6
  27.     CALL    \1
  28.     ENDM
  29. *************************************************
  30. CrunchOnly    equ    1
  31. DecrunchOnly    equ    2
  32. ExtraMemLen    equ    100
  33. *************************************************
  34. main:
  35.     lea    CommandLine(pc),a1
  36.     movem.l    d0/a0,(a1)        ;save CLI-Parameters
  37.  
  38. ** Open dos.library: **
  39.     lea    DOSName(pc),a1
  40.     CALLEXEC OldOpenLibrary
  41.     lea    _DOSBase(pc),a0
  42.     move.l    d0,(a0)
  43.     beq.s    .End
  44.  
  45. ** Get output handle: **
  46.     move.l    d0,a6
  47.     CALL    Output
  48.     lea    OutHandle(pc),a0
  49.     move.l    d0,(a0)
  50.     beq.s    .CloseDOS
  51.  
  52. ** Open CrM.library: **
  53.     lea    CrMName(pc),a1
  54.     moveq    #4,d0
  55.     CALLEXEC OpenLibrary
  56.     lea    _CrMBase(pc),a0
  57.     move.l    d0,(a0)
  58.     beq.s    .CloseDOS
  59.  
  60. ** Do all actions: **
  61.     bsr.s    mainloop
  62.  
  63. ** Close CrM.library: **
  64.     move.l    _CrMBase(pc),a1
  65.     CALLEXEC CloseLibrary
  66. ** Close dos.library: **
  67. .CloseDOS:
  68.     move.l    _DOSBase(pc),a1
  69.     CALLEXEC CloseLibrary
  70. ** Return to the CLI: **
  71. .End:    moveq    #0,d0
  72.     rts
  73. *----------
  74. mainloop:
  75.     lea    InitTxt(pc),a0
  76.     bsr.w    PrintText
  77.  
  78. ** Analyse Commandline: **
  79.     movem.l    CommandLine(pc),d1/a1    ;get Parameters
  80.     clr.b    -1(a1,d1.w)        ;replace <cr> by Null
  81.     move.b    (a1),d0
  82.     beq.w    .usage            ;no Parameters
  83.     cmp.b    #"?",d0
  84.     beq.w    .usage            ;question mark -> print usage
  85.     lea    Algorithm(pc),a2
  86.     move.w    (a2),d1            ;default Algorithm
  87.     cmp.b    #"-",d0
  88.     bne.w    .noopts            ;no option specified
  89.     addq.l    #1,a1
  90.  
  91. ** Optionsloop: processes all options, no spaces between options are allowed!
  92. .optsloop:
  93.     move.b    (a1)+,d0        ;get char
  94.     beq.w    .usage
  95.     cmp.b    #" ",d0
  96.     beq.w    .noopts            ;no more options
  97.  
  98.     cmp.b    #"1",d0
  99.     beq.s    .norm
  100.     cmp.b    #"2",d0
  101.     beq.s    .lzh
  102.     cmp.b    #"c",d0
  103.     beq.s    .crunch
  104.     cmp.b    #"d",d0
  105.     beq.s    .decrunch
  106.     cmp.b    #"f",d0
  107.     beq.s    .flash
  108.     cmp.b    #"l",d0
  109.     beq.s    .longer
  110.     cmp.b    #"s",d0
  111.     beq.s    .sample
  112.     cmp.b    #"y",d0
  113.     beq.s    .encrypt
  114.     lea    UnknownOpt(pc),a0
  115.     move.b    d0,(a0)
  116.     lea    UnknownOptTxt(pc),a0
  117.     bsr.w    PrintText
  118.     bra.s    .optsloop
  119. *-----
  120. .norm:    and.w    #$fff0,d1        ;kill old algorithm
  121.     or.w    #cm_Normal,d1        ;new algo
  122.     bra.s    .optsloop
  123. *-----
  124. .lzh:    and.w    #$fff0,d1        ;kill old algorithm
  125.     or.w    #cm_LZH,d1        ;new algo
  126.     bra.s    .optsloop
  127. *-----
  128. .crunch:
  129.     lea    Operation(pc),a0
  130.     move.b    #CrunchOnly,(a0)
  131.     bra.s    .optsloop
  132. *-----
  133. .decrunch:
  134.     lea    Operation(pc),a0
  135.     move.b    #DecrunchOnly,(a0)
  136.     bra.s    .optsloop
  137. *-----
  138. .flash:
  139.     bset    #cmB_LEDFlash,d1
  140.     bra.s    .optsloop
  141. *-----
  142. .longer:
  143.     lea    LongerFileFlag(pc),a0
  144.     st    (a0)
  145.     bra.w    .optsloop
  146. *-----
  147. .sample:
  148.     bset    #cmB_Sample,d1
  149.     bra.w    .optsloop
  150. *-----
  151. .encrypt:
  152.     bset    #cmB_PW,d1
  153.     bra.w    .optsloop
  154. *-----
  155. .noopts:
  156.     move.w    d1,(a2)            ;algorithm
  157.     lea    SourceName(pc),a0
  158.     move.l    a1,(a0)
  159.     lea    DestName(pc),a0        ;normally Source- and DestName are
  160.     move.l    a1,(a0)            ;the same...
  161. .search:
  162.     move.b    (a1)+,d0
  163.     beq.s    .samedest        ;no second filename
  164.     cmp.b    #" ",d0
  165.     bne.s    .search
  166.     move.l    a1,(a0)            ;new DestName
  167.     clr.b    -1(a1)            ;replace <Space> by Null
  168. .samedest:
  169.  
  170. ** Open Sourcefile: **
  171.     move.l    SourceName(pc),d1
  172.     move.l    #MODE_OLDFILE,d2
  173.     CALLDOS    Open
  174.     move.l    d0,d5
  175.     beq.w    .srcnotopen
  176.  
  177. ** Read DataHeader (first 14 Bytes in the file): **
  178.     move.l    d5,d1
  179.     lea    DataHdr(pc),a0
  180.     move.l    a0,d2
  181.     moveq    #14,d3
  182.     CALL    Read
  183.  
  184.     lea    DataHdr(pc),a0
  185.     CALLCRM    cmCheckCrunched
  186.     lea    Operation(pc),a0
  187.     tst.l    d0
  188.     beq.s    .loadnormal        ;file is not crunched with CrM
  189.     cmp.b    #CrunchOnly,(a0)
  190.     beq.w    .alreadycrunched    ;can't crunch twice!
  191.     move.b    #DecrunchOnly,(a0)
  192.     bsr.w    CrunchedLoad        ;load crunched file
  193.     bra.s    .crloadcont
  194. .loadnormal:
  195.     cmp.b    #DecrunchOnly,(a0)
  196.     beq.w    .notcrunched
  197.     move.b    #CrunchOnly,(a0)
  198.     bsr.w    NormalLoad        ;load original file
  199. .crloadcont:
  200.     move.l    d0,-(sp)        ;save return code
  201.     move.l    d5,d1
  202.     CALLDOS    Close            ;close Sourcefile
  203.     move.l    (sp)+,d0
  204.     beq.s    .done            ;loading failed!
  205.  
  206.     move.b    Operation(pc),d0
  207.     cmp.b    #DecrunchOnly,d0
  208.     bne.s    .nodecr
  209.     bsr.w    DecrunchIt        ;decrunch data
  210.     beq.s    .done
  211. .nodecr:
  212.     move.b    Operation(pc),d0
  213.     cmp.b    #DecrunchOnly,d0
  214.     bne.s    .nodecrsave
  215.     bsr.w    DecrunchedSave        ;save original data
  216. .nodecrsave:
  217.     move.b    Operation(pc),d0
  218.     cmp.b    #CrunchOnly,d0
  219.     bne.s    .nocr
  220.     bsr.w    CrunchIt        ;crunch data
  221.     beq.s    .done
  222. .nocr:
  223.     move.b    Operation(pc),d0
  224.     cmp.b    #CrunchOnly,d0
  225.     bne.s    .nocrsave
  226.     bsr.w    CrunchedSave        ;save crunched data
  227. .nocrsave:
  228.  
  229. .done:
  230. ** Free cmCrunchStruct: **
  231.     move.l    CrStruct(pc),d0
  232.     beq.s    .nocrstruct        ;no cmCrunchStruct allocated
  233.     move.l    d0,a1
  234.     moveq    #cm_FreeStruct,d0
  235.     CALLCRM    cmProcessCrunchStructA
  236. .nocrstruct:
  237. ** Free Buffer: **
  238.     move.l    MemBase(pc),a1
  239.     move.l    MemLen(pc),d0
  240.     beq.s    .End
  241.     CALLEXEC FreeMem
  242. .End:    rts
  243. *-------
  244. ** Sourcefile open failed! **
  245. .srcnotopen:
  246.     move.l    SourceName(pc),a0
  247.     move.l    a0,-(sp)
  248.     lea    NotOpenTxt(pc),a0
  249.     move.l    sp,a1
  250.     bsr.s    RawPrintText
  251.     addq.l    #4,sp
  252.     rts
  253. *-------
  254. ** DecrunchOnly: File is not crunched **
  255. .notcrunched:
  256.     lea    NotCrunchedTxt(pc),a0
  257. .acrcont:
  258.     move.l    SourceName(pc),-(sp)
  259.     move.l    sp,a1
  260.     bsr.s    RawPrintText
  261.     addq.l    #4,sp
  262.     moveq    #0,d0
  263.     bra.w    .crloadcont
  264. *-----
  265. ** CrunchOnly: File is already crunched **
  266. .alreadycrunched:
  267.     lea    AlreadyCrTxt(pc),a0
  268.     bra.s    .acrcont
  269. *-------
  270. ** Print Usage: **
  271. .usage:    lea    UsageTxt(pc),a0
  272. ;    bra.s    PrintText
  273. ********************************
  274. ** Print some text to the CLI **
  275. PrintText:    ** a0:Text
  276.     movem.l    d0-d3/a0-a1/a6,-(sp)
  277.     move.l    a0,d2
  278.     move.l    OutHandle(pc),d1
  279.     moveq    #-1,d3
  280. .count:    addq.l    #1,d3
  281.     tst.b    (a0)+
  282.     bne.s    .count
  283.     CALLDOS    Write
  284.     movem.l    (sp)+,d0-d3/a0-a1/a6
  285.     rts
  286. *----------
  287. ** Print some text to the CLI with formatting using RawDoFmt(): **
  288. RawPrintText:    ** a0:Text a1:Args
  289.     movem.l    d0-d2/a0-a3/a6,-(sp)
  290.     lea    .stuffchar(pc),a2
  291.     lea    InitTxt(pc),a3
  292.     CALLEXEC RawDoFmt
  293.     lea    InitTxt(pc),a0
  294.     bsr.s    PrintText        ;print the converted text
  295.     movem.l    (sp)+,d0-d2/a0-a3/a6
  296.     rts
  297. *-----
  298. .stuffchar:
  299.     move.b    d0,(a3)+        ;put data to output string
  300.     rts
  301. *****************************
  302. ** Load a file to crunch it. A cmCrunchStruct and the Buffer for the file
  303. ** will be allocated.
  304. NormalLoad:
  305. ** Get Lock on the Sourcefile: **
  306.     move.l    SourceName(pc),d1
  307.     moveq    #ACCESS_READ,d2
  308.     CALLDOS    Lock
  309.     move.l    d0,d4
  310.     beq.w    .notopen        ;locking failed!
  311.  
  312. ** Examine Sourcefile: **
  313.     move.l    d4,d1
  314.     lea    InitTxt(pc),a0        ;InitTxt serves as buffer for the fib
  315.     move.l    a0,d2
  316.     CALL    Examine
  317.     move.l    d0,-(sp)        ;save result on the stack
  318.  
  319. ** UnLock Sourcefile: **
  320.     move.l    d4,d1
  321.     CALL    UnLock
  322.     move.l    (sp)+,d0
  323.     beq.w    .notopen        ;examining failed!
  324.     lea    InitTxt(pc),a0
  325.     move.l    fib_Size(a0),d7        ;Size of Sourcefile
  326.  
  327. ** Allocate Buffer (Len=Sourcefilelength+ExtraMemLen): **
  328.     moveq    #ExtraMemLen,d0
  329.     add.l    d7,d0
  330.     lea    MemLen(pc),a0
  331.     move.l    d0,(a0)
  332.     moveq    #0,d1
  333.     CALLEXEC AllocMem
  334.     lea    MemBase(pc),a0
  335.     move.l    d0,(a0)
  336.     beq.w    .nomem            ;not enough memory
  337.  
  338. ** Allocate a cmCrunchStruct: **
  339.     clr.l    -(sp)            ;TAG_DONE
  340.     move.w    Algorithm(pc),-(sp)
  341.     clr.w    -(sp)
  342.     move.l    #CMCS_Algo,-(sp)
  343.     move.l    sp,a0
  344.     moveq    #cm_AllocStruct,d0
  345.     CALLCRM    cmProcessCrunchStructA
  346.     lea    12(sp),sp
  347.     lea    CrStruct(pc),a0
  348.     move.l    d0,(a0)
  349.     beq.s    .nomem            ;allocating failed
  350.  
  351.     move.l    d7,-(sp)
  352.     move.l    SourceName(pc),a0
  353.     move.l    a0,-(sp)
  354.     lea    LoadingTxt(pc),a0
  355.     move.l    sp,a1
  356.     bsr.w    RawPrintText
  357.     addq.l    #8,sp
  358.  
  359. ** Copy DataHeader to Buffer **
  360.     move.l    MemBase(pc),a1
  361.     add.w    #ExtraMemLen,a1
  362.     lea    DataHdr(pc),a0
  363.     move.l    (a0)+,(a1)+
  364.     move.l    (a0)+,(a1)+
  365.     move.l    (a0)+,(a1)+
  366.     move.w    (a0)+,(a1)+
  367.  
  368. ** Load rest of sourcefile **
  369.     move.l    d5,d1
  370.     move.l    a1,d2
  371.     move.l    d7,d3
  372.     subq.l    #8,d3
  373.     subq.l    #6,d3
  374.     CALLDOS    Read
  375.     cmp.l    d0,d3
  376.     bne.s    .readerr        ;readerror
  377.  
  378.     lea    OrigLen(pc),a0
  379.     move.l    d7,(a0)            ;Originallen (Length of Sourcefile)
  380.     lea    ReturnTxt(pc),a0
  381.     bsr.w    PrintText
  382.  
  383.     moveq    #1,d0            ;return: TRUE
  384.     rts
  385. *-----
  386. ** Opening failed: **
  387. .notopen:
  388.     move.l    SourceName(pc),a0
  389.     move.l    a0,-(sp)
  390.     lea    NotOpenTxt(pc),a0
  391.     move.l    sp,a1
  392.     bsr.w    RawPrintText
  393.     addq.l    #4,sp
  394. .Exit:    moveq    #0,d0            ;return: FALSE
  395.     rts
  396. *-----
  397. ** not enough memory available: **
  398. .nomem:    lea    MemLen(pc),a0
  399.     clr.l    (a0)
  400.     lea    NoMemTxt(pc),a0
  401. .prtx:    bsr.w    PrintText
  402.     bra.s    .Exit
  403. ** readerror: **
  404. .readerr:
  405.     lea    ReadErrTxt(pc),a0
  406.     bra.s    .prtx
  407. *------------
  408. ** Crunch Data: **
  409. CrunchIt:
  410.     lea    CrunchingTxt(pc),a0
  411.     bsr.w    PrintText
  412.  
  413.     move.l    CrStruct(pc),a0
  414.     move.l    MemBase(pc),a1
  415.     move.l    a1,cmcr_Dest(a0)
  416.     moveq    #ExtraMemLen,d0
  417.     add.l    d0,a1
  418.     move.l    a1,cmcr_Src(a0)
  419.     move.l    OrigLen(pc),d1
  420.     move.l    d1,cmcr_SrcLen(a0)
  421.     add.l    d0,d1
  422.     move.l    d1,cmcr_DestLen(a0)
  423.     lea    DataHdr(pc),a1
  424.     move.l    a1,cmcr_DataHdr(a0)
  425.     clr.l    cmcr_DisplayHook(a0)
  426.     move.w    #$7ffe,cmcr_DisplayStep(a0)
  427.     CALLCRM    cmCrunchData
  428.  
  429.     lea    CrLen(pc),a0
  430.     move.l    d0,(a0)
  431.     beq.s    .error            ;error while crunching
  432.  
  433. ** calculate gain in percent: you have to do this complicated rotating
  434. ** because there is no longword division available on a standard 68000
  435. ** this routine is not very cool, it will produce shit when the gain is
  436. ** negative. (Problem now fixed).
  437.     move.l    OrigLen(pc),d1
  438.     move.l    d1,d2
  439.     move.l    d1,d3
  440.     moveq    #0,d4
  441.     sub.l    d0,d2            ;gain
  442.     bpl.s    .rotloop
  443.     neg.l    d2
  444.     moveq    #1,d4
  445. .rotloop:
  446.     tst.l    d2
  447.     bmi.s    .rotend
  448.     tst.l    d3
  449.     bmi.s    .rotend
  450.     add.l    d2,d2
  451.     add.l    d3,d3
  452.     bra.s    .rotloop
  453. .rotend:
  454.     lsr.l    #1,d2
  455.     lsr.l    #1,d3
  456.     clr.w    d2
  457.     clr.w    d3
  458.     swap    d2
  459.     swap    d3
  460.     mulu    #100,d2
  461.     divu    d3,d2
  462.     tst.w    d4
  463.     beq.s    .noneg
  464.     neg.w    d2
  465. .noneg:    move.w    d2,-(sp)
  466.     move.l    d0,-(sp)
  467.     move.l    d1,-(sp)
  468.     move.l    sp,a1
  469.     lea    CrunchedTxt(pc),a0
  470.     bsr.w    RawPrintText
  471.     lea    10(sp),sp
  472.     moveq    #1,d0            ;return: TRUE
  473.     rts
  474.  
  475. ** error while crunchung: **
  476. .error:    move.l    CrStruct(pc),a0
  477.     move.b    cmcr_QuitFlag(a0),d0
  478.     lea    AbortTxt(pc),a0
  479.     cmp.b    #"a",d0
  480.     beq.s    .errend        ;crunching was aborted (not possible yet)
  481.     lea    NotCrTxt(pc),a0
  482.     cmp.b    #"n",d0
  483.     beq.s    .errend        ;data is not crunchable (or already
  484.                 ;crunched with another packer)
  485.     lea    UnknownErrTxt(pc),a0
  486. .errend:
  487.     bsr.w    PrintText
  488.     moveq    #0,d0        ;return: FALSE
  489.     rts
  490. *----------
  491. ** Save crunched data: **
  492. CrunchedSave:
  493. ** Open Destination file: **
  494.     move.l    OrigLen(pc),d0
  495.     sub.l    CrLen(pc),d0
  496.     subq.l    #8,d0
  497.     subq.l    #6,d0
  498.     bgt.s    .cont
  499.     move.b    LongerFileFlag(pc),d0
  500.     bne.s    .cont            ;keep longer files
  501.     lea    TooLongFileTxt(pc),a0
  502.     bra.w    RawPrintText
  503. *-----
  504. .cont:    move.l    DestName(pc),d1
  505.     move.l    #MODE_NEWFILE,d2
  506.     CALLDOS    Open
  507.     move.l    d0,d5
  508.     beq.s    .notopen        ;open failed
  509.  
  510.     moveq    #14,d0
  511.     add.l    CrLen(pc),d0
  512.     move.l    d0,-(sp)
  513.     move.l    DestName(pc),-(sp)
  514.     move.l    sp,a1
  515.     lea    SavingTxt(pc),a0
  516.     bsr.w    RawPrintText
  517.     addq.l    #8,sp
  518.  
  519. ** Write DataHeader: **
  520.     move.l    d5,d1
  521.     lea    DataHdr(pc),a0
  522.     move.l    a0,d2
  523.     moveq    #14,d3
  524.     CALL    Write            ;DataHeader
  525.     tst.l    d0
  526.     bmi.s    .error            ;writeerror
  527.  
  528. ** Write crunched Data: **
  529.     move.l    d5,d1
  530.     move.l    MemBase(pc),d2
  531.     move.l    CrLen(pc),d3
  532.     CALL    Write            ;Data
  533.     tst.l    d0
  534.     bmi.s    .error            ;writeerror
  535.  
  536. ** Close Destination file: **
  537.     move.l    d5,d1
  538.     CALL    Close
  539.  
  540. ** Generate Comment: **
  541.     lea    Comment(pc),a0
  542.     move.l    OrigLen(pc),-(sp)
  543.     move.l    sp,a1
  544.     lea    .stuffchar(pc),a2
  545.     lea    InitTxt(pc),a3        ;again InitTxt serves as a temporary
  546.                     ;buffer
  547.     CALLEXEC RawDoFmt
  548.     addq.l    #4,sp
  549.  
  550. ** Set Comment (for RTDD): **
  551.     move.l    DestName(pc),d1
  552.     lea    InitTxt(pc),a0
  553.     move.l    a0,d2
  554.     CALLDOS    SetComment
  555.  
  556.     lea    ReturnTxt(pc),a0
  557.     bra.w    PrintText        ;print texte and return (no returncode)
  558. *-----
  559. ** Destfile open failed: **
  560. .notopen:
  561.     move.l    DestName(pc),-(sp)
  562.     move.l    sp,a1
  563.     lea    NotOpenTxt(pc),a0
  564.     bsr.w    RawPrintText
  565.     addq.l    #4,sp
  566.     rts
  567. *-----
  568. ** writeerror: **
  569. .error:    lea    ErrorWriteTxt(pc),a0
  570.     bsr.w    PrintText
  571.  
  572. ** close destfile: **
  573.     move.l    d5,d1
  574.     CALL    Close
  575.  
  576. ** delete destfile: **
  577.     move.l    DestName(pc),d1
  578.     CALL    DeleteFile
  579.     rts
  580. *-----
  581. .stuffchar:
  582.     move.b    d0,(a3)+        ;put data to output string
  583.     rts
  584. *****************************
  585. ** Load data to decrunch (Buffer will be allocated): **
  586. CrunchedLoad:
  587. ** Copy contents of DataHeader to internal Variables: **
  588.     lea    DataHdr(pc),a0
  589.     lea    OrigLen(pc),a1
  590.     move.l    dh_OriginalLen(a0),(a1)
  591.     lea    CrLen(pc),a1
  592.     move.l    dh_CrunchedLen(a0),(a1)
  593.  
  594. ** Allocate Buffer (len=OrigLen+MinSecDist): **
  595.     moveq    #0,d0
  596.     move.w    dh_MinSecDist(a0),d0
  597.     add.l    dh_OriginalLen(a0),d0
  598.     lea    MemLen(pc),a0
  599.     move.l    d0,(a0)
  600.     moveq    #0,d1
  601.     CALLEXEC AllocMem
  602.     lea    MemBase(pc),a0
  603.     move.l    d0,(a0)
  604.     beq.w    .nomem            ;not enough memory
  605.  
  606.     moveq    #14,d0
  607.     add.l    CrLen(pc),d0
  608.     move.l    d0,-(sp)
  609.     move.l    SourceName(pc),-(sp)
  610.     move.l    sp,a1
  611.     lea    LoadingTxt(pc),a0
  612.     bsr.w    RawPrintText
  613.     addq.l    #8,sp
  614.  
  615. ** Read crunched Data: **
  616.     move.l    d5,d1
  617.     move.l    MemBase(pc),d2
  618.     move.l    CrLen(pc),d3
  619.     CALLDOS    Read
  620.     cmp.l    d0,d3
  621.     bne.s    .readerr        ;readerror
  622.  
  623.     moveq    #1,d0            ;return: TRUE
  624.     lea    ReturnTxt(pc),a0
  625.     bra.s    .prtx
  626. *-----
  627. .readerr:
  628.     moveq    #0,d0            ;return: FALSE
  629.     lea    ReadErrTxt(pc),a0
  630.     bra.s    .prtx
  631. *-----
  632. .nomem:    lea    MemLen(pc),a0
  633.     clr.l    (a0)
  634.     moveq    #0,d0            ;return: FALSE
  635.     lea    NoMemTxt(pc),a0
  636. .prtx:    bra.w    PrintText
  637. *------------
  638. ** Decrunch Data: **
  639. DecrunchIt:
  640.     move.l    OrigLen(pc),-(sp)
  641.     move.l    CrLen(pc),-(sp)
  642.     move.l    sp,a1
  643.     lea    DecrunchingTxt(pc),a0
  644.     bsr.w    RawPrintText
  645.     addq.l    #8,sp
  646.  
  647.     lea    DataHdr(pc),a2
  648.     move.l    MemBase(pc),a0
  649.     move.w    dh_MinSecDist(a2),d0
  650.     lea    0(a0,d0.w),a1
  651.     CALLCRM    cmDecrunch
  652.     tst.l    d0
  653.     beq.s    .error
  654.  
  655.     lea    ReturnTxt(pc),a0
  656.     bsr.w    PrintText
  657.     moveq    #1,d0            ;return: TRUE
  658.     rts
  659. *-----
  660. ** error while decrunching: **
  661. .error:
  662.     lea    DecrErrorTxt(pc),a0
  663.     bsr.w    PrintText
  664.     moveq    #0,d0            ;return: FALSE
  665.     rts
  666. *----------
  667. ** Save original (decrunched) file: **
  668. DecrunchedSave:
  669. ** Open Destination file: **
  670.     move.l    DestName(pc),d1
  671.     move.l    #MODE_NEWFILE,d2
  672.     CALLDOS    Open
  673.     move.l    d0,d5
  674.     beq.s    .notopen        ;openfail
  675.  
  676.     move.l    OrigLen(pc),-(sp)
  677.     move.l    DestName(pc),-(sp)
  678.     move.l    sp,a1
  679.     lea    SavingTxt(pc),a0
  680.     bsr.w    RawPrintText
  681.     addq.l    #8,sp
  682.  
  683. ** Write Data: **
  684.     move.l    d5,d1
  685.     lea    DataHdr(pc),a0
  686.     moveq    #0,d2
  687.     move.w    dh_MinSecDist(a0),d2
  688.     add.l    MemBase(pc),d2
  689.     move.l    OrigLen(pc),d3
  690.     CALL    Write            ;Data
  691.     tst.l    d0
  692.     bmi.s    .error            ;writeerror
  693.  
  694. ** Close File: **
  695.     move.l    d5,d1
  696.     CALL    Close
  697.  
  698.     lea    ReturnTxt(pc),a0
  699.     bra.w    PrintText        ;print text and return (no returncode)
  700. *-----
  701. ** destfile could not be opened: **
  702. .notopen:
  703.     move.l    DestName(pc),-(sp)
  704.     move.l    sp,a1
  705.     lea    NotOpenTxt(pc),a0
  706.     bsr.w    RawPrintText
  707.     addq.l    #4,sp
  708.     rts
  709. *-----
  710. ** writeerror: **
  711. .error:    lea    ErrorWriteTxt(pc),a0
  712.     bsr.w    PrintText
  713.  
  714. ** Close destfile: **
  715.     move.l    d5,d1
  716.     CALL    Close
  717.  
  718. ** Delete destfile: **
  719.     move.l    DestName(pc),d1
  720.     CALL    DeleteFile
  721.     rts
  722. *************************************************
  723. _DOSBase:    dc.l    0
  724. _CrMBase:    dc.l    0
  725. OutHandle:    dc.l    0        ;Handle to print text in the CLI
  726. MemBase:    dc.l    0        ;Start of Buffer
  727. MemLen:        dc.l    0        ;Length of Buffer
  728. OrigLen:    dc.l    0        ;Original Length of Data
  729. CrLen:        dc.l    0        ;Crunched Length if Data
  730. CrStruct:    dc.l    0        ;struct cmCrunchStruct *
  731. CommandLine:    dc.l    0,0        ;CLI-Parameters (text *, len)
  732. SourceName:    dc.l    0        ;Sourcefilename *
  733. DestName:    dc.l    0        ;Destinationfilename *
  734. DataHdr:    ds.b    14        ;struct DataHeader
  735. Algorithm:    dc.w    cm_LZH!cmF_Overlay    ;Algorithm for cmcs_Algo Tag
  736. Operation:    dc.b    0        ;type of Operation (CrunchOnly,
  737.                     ;DecrunchOnly or NULL for auto)
  738. LongerFileFlag:    dc.b    0        ;keep longer files?
  739. DOSName:    dc.b    "dos.library",0
  740. CrMName:    CRMNAME
  741.         cnop    0,4
  742. InitTxt:    dc.b    27,"[33;1mCrMData ",27,"[0;33mV1.01 ",27,"[0m--- "
  743.         dc.b    27,"[32m(c) 1993 Thomas Schwarz",27,"[0m",10,10,0
  744.         dc.b    "$VER: CrMData 1.01",0
  745. UsageTxt:    dc.b    "Usage: CrMData [-12cdfsy] <sourcefile> [<destfile>]",10
  746.         dc.b    "-1 : use CrM-Normal algorithm",10
  747.         dc.b    "-2 : use LZ-Huffman algorithm",10
  748.         dc.b    "-c : crunch only",10
  749.         dc.b    "-d : decrunch only",10
  750.         dc.b    "-f : enable Power-LED flashing",10
  751.         dc.b    "-l : save file, even if it becomes longer",10
  752.         dc.b    "-s : use Sample-Mode",10
  753.         dc.b    "-y : enable password encryption",10,0
  754. UnknownOptTxt:    dc.b    "Unknown option: -"
  755. UnknownOpt:    dc.b    " !"
  756. ReturnTxt:    dc.b    10,0
  757. NotOpenTxt:    dc.b    "Could not open `%s'!",10,0
  758. LoadingTxt:    dc.b    "Loading `%s' (%ld bytes)...",0
  759. NoMemTxt:    dc.b    "Not enough memory available!",10,0
  760. ReadErrTxt:    dc.b    "Read Error!",10,0
  761. NotCrunchedTxt:    dc.b    "Can't decrunch `%s': File is not crunched!",10,0
  762. AlreadyCrTxt:    dc.b    "Can't crunch `%s': File is already crunched!",10,0
  763. CrunchingTxt:    dc.b    "Crunching...",0
  764. CrunchedTxt:    dc.b    " %ld -> %ld (%d%% gain)",10,0
  765. AbortTxt:    dc.b    "Crunching aborted!",10,0
  766. NotCrTxt:    dc.b    "File not crunchable!",10,0
  767. UnknownErrTxt:    dc.b    "Strange error occurred while crunching!",10,0
  768. SavingTxt:    dc.b    "Saving `%s' (%ld bytes)...",0
  769. ErrorWriteTxt:    dc.b    " Error while writing!",10,0
  770. Comment:    dc.b    "CrM!%08lx",0
  771. DecrunchingTxt:    dc.b    "Decrunching (%ld -> %ld)...",0
  772. DecrErrorTxt:    dc.b    " Error while decrunching!",10,0
  773. TooLongFileTxt:    dc.b    "File not saved: crunched file is longer than original",10,0
  774.  
  775.